package com.tortuousroad.framework.web.controller;

import com.tortuousroad.framework.spring.web.bind.support.DateConvertEditor;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import javax.servlet.http.HttpServletRequest;
import java.time.temporal.Temporal;

/**
 * @author 孙许
 * @date 2018-07-09
 * @description Controller基类
 * initBinder参考 《精通spring4.x》591页
 * 添加自定义的编辑器DateConvertEditor
 */
public abstract class BaseController {

    @InitBinder
    protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
        binder.registerCustomEditor(Temporal.class, new DateConvertEditor());
    }
}
